package com.alfa.myworld.client;

import java.util.ArrayList;
import java.util.List;
import com.alfa.myworld.shared.UserDto;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class UsersTablePopUp extends Composite{

	private static UsersTablePopUpUiBinder uiBinder = GWT.create(UsersTablePopUpUiBinder.class);
	
	interface UsersTablePopUpUiBinder extends UiBinder<Widget, UsersTablePopUp> {
	}

	public UsersTablePopUp() {
		populateTable(); 
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField(provided=true) 
	CellTable<UserDto> cellTable = new CellTable<UserDto>();
	@UiField 
	Button btnClose;

	
	private void populateTable(){
		TextColumn<UserDto> firstNameCol = new TextColumn<UserDto>() {
			@Override
			public String getValue(UserDto object) {
				return object.getFirstName();
			}
		};
		TextColumn<UserDto> lastNameCol = new TextColumn<UserDto>() {
			@Override
			public String getValue(UserDto object) {
				return object.getLastName(); 
			}
		};
		
		cellTable.addColumn(firstNameCol);
		cellTable.addColumn(lastNameCol);
		
		List<UserDto> list = new ArrayList<UserDto>(); 
		UserDto user1 = new UserDto(); 
		user1.setFirstName("john");
		user1.setLastName("smith");
		UserDto user2 = new UserDto(); 
		user2.setFirstName("juan");
		user2.setLastName("perez");
		list.add(user1);
		list.add(user2);
		
		cellTable.setRowData(list);
	}
	
	@UiHandler("btnClose")
	void onButtonClick(ClickEvent event) {
		//TODO terminar esto. 
		RootPanel.getBodyElement().getElementsByTagName("dialogList");
	}
}
